package android.slc.appbase.utils;

import android.slc.appbase.R;
import android.slc.appbase.config.ConstantsBase;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;

/**
 * @author slc
 * @date 2020-08-25 10:17
 */
public class FastTimeFormatUtils {
    public static String[] sexArray = StringUtils.getStringArray(R.array.app_sex_array);
    public static String[] maritalStatusArray = StringUtils.getStringArray(R.array.app_marital_status);

    public static String toSex(int sex) {
        return sexArray[sex];
    }

    public static String toMaritalStatus(boolean maritalStatus) {
        return maritalStatusArray[maritalStatus ? 1 : 0];
    }

    /**
     * 日期转UI年月
     *
     * @param date
     * @return
     */
    public static String toUiY2MC(String date) {
        if (StringUtils.isEmpty(date)) {
            return "";
        }
        return TimeUtils.millis2String(TimeUtils.string2Millis(date, ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_MC_COMMON), ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_MC_CH);
    }

    /**
     * 日期转UI年月日
     *
     * @param date
     * @return
     */
    public static String toUiY2D(String date) {
        if (StringUtils.isEmpty(date)) {
            return "";
        }
        return TimeUtils.millis2String(TimeUtils.string2Millis(date, ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_D_COMMON), ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_D_CH);
    }

    /**
     * 日期转UI日期+时分
     *
     * @param date
     * @return
     */
    public static String toUiY2M(String date) {
        if (StringUtils.isEmpty(date)) {
            return "";
        }
        return TimeUtils.millis2String(TimeUtils.string2Millis(date, ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_M_COMMON), ConstantsBase.Value.VALUE_TIME_PATTERN_BY_Y_M_CH);
    }

    /**
     * 日期转时分
     *
     * @param date
     * @return
     */
    public static String toUiH2M(String date) {
        if (StringUtils.isEmpty(date)) {
            return "";
        }
        return TimeUtils.millis2String(TimeUtils.string2Millis(date), ConstantsBase.Value.VALUE_TIME_PATTERN_BY_H_M_COMMON);
    }

    public static String toAmOrPm(int index) {
        switch (index) {
            case ConstantsBase.Value.VALUE_AM:
                return StringUtils.getString(R.string.app_label_am);
            case ConstantsBase.Value.VALUE_PM:
                return StringUtils.getString(R.string.app_label_pm);
            case ConstantsBase.Value.VALUE_FULL:
                return StringUtils.getString(R.string.app_label_am_pm_full);
        }
        return StringUtils.getString(R.string.app_label_am_pm_error);
    }

    public static String toUiAndAmOrPm(String date, int index) {
        return toUiY2D(date) + toAmOrPm(index);
    }
}
